#ifndef REACTOR_MSGSERVER_H
#define REACTOR_MSGSERVER_H

#include <QObject>
#include <QVector>
#include "tcpserver.h"
#include "reactor_msgsocket.h"

class Reactor_MsgServer: public QObject
{
    Q_OBJECT
signals:
    void signalDownloadFile(const QJsonValue &json);
    void signalUserStatus(const QString &text);
public slots:
    void SltTransFileToClient(const int &userId, const QJsonValue &json);
    void SltConnected();
    void SltDisConnected();
    void SltMsgToClient(const quint8 &type, const int &id, const QJsonValue &json);

public:
    ///MsgServer创建时需要和EvLoop,TdPool绑定使用
    explicit Reactor_MsgServer(int port, EventLoop *loop,
                               ThreadPool *pool = 0, QObject *parent = nullptr);
    ~Reactor_MsgServer();
    bool startListen(void);

private:
    ///使用Reactor_MsgSocket
    QVector<Reactor_MsgSocket *> m_clients;
    TcpServer *m_server; ///使用Reactor中的TcpServer
    void newTcpConnection(TcpSocket *socket); ///新连接请求时的回调函数
};

#endif // REACTOR_MSGSERVER_H
